package com.example.jetpack04;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import com.example.jetpack04.databinding.ActivityScoreBinding;
import com.example.jetpack04.viewmodel.ScoreViewModel;

public class ScoreActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_score);

        ActivityScoreBinding activityScoreBinding = DataBindingUtil.setContentView(this, R.layout.activity_score);
        ScoreViewModel  scoreViewModel = new ViewModelProvider(this, new ViewModelProvider.AndroidViewModelFactory(this.getApplication())).get(ScoreViewModel.class);
        activityScoreBinding.setScorevm(scoreViewModel);
        //如果没有这一句 实现不了双向绑定
        activityScoreBinding.setLifecycleOwner(this);
    }
}